/*
 * @Description: 全局路由入口及路由权限拦截
 *
 * @Date: 2021-03-02 15:07:27
 */
import Vue from 'vue'
import Router from 'vue-router'

import production from './production'
import group from './group'
import notice from './notice'

Vue.use(Router)

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
//push
Router.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
	return originalPush.call(this, location).catch((err) => err)
}
//replace
Router.prototype.replace = function push(location, onResolve, onReject) {
	if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
	return originalReplace.call(this, location).catch((err) => err)
}

let router = new Router({
	mode: 'history',
	base: process.env.BASE_URL,
	routes: [...production, ...group, ...notice],
})

export default router
